%div

  - if User.current.git_allowed_to?(:create_repository_deployment_credentials, @repository)
    .contextual
      - css_class = (!@user_keys.empty? || !@other_keys.empty?) ? 'modal-box' : 'modal-box-close-only'
      = link_to l(:label_deployment_credential_add), new_repository_deployment_credential_path(@repository), class: "icon icon-add #{css_class}"

  %h3= l(:label_deployment_credentials)

  - if @repository_deployment_credentials.any?

    %table{ class: 'table table-hover' }
      %thead
        %tr
          %th= l(:label_deployment_credential_owner)
          %th= l(:label_deployment_credential_public_key_name)
          %th= l(:label_deployment_credential_public_key_file)
          %th= l(:label_deployment_credential_permissions)
          %th= l(:label_deployment_credential_honored)
          %th= l(:label_deployment_credential_active)
          %th

      %tbody
        - @repository_deployment_credentials.sort_by {|x| [x.user.login, x.gitolite_public_key.title]}.each do |credential|
          %tr
            %td= credential.user.login
            %td
              - if credential.user == User.current
                = link_to(credential.gitolite_public_key.title, url_for(controller: 'my', action: 'account', public_key_id: credential.gitolite_public_key.id))
              - elsif User.current.admin?
                = link_to(credential.gitolite_public_key.title, url_for(controller: 'users', action: 'edit', id: credential.user.id, public_key_id: credential.gitolite_public_key.id, tab: 'keys'))
              - else
                = credential.gitolite_public_key.title

            %td= credential.gitolite_public_key.gitolite_path
            %td= credential.perm
            %td= checked_image2 credential.honored?
            %td= checked_image2 credential.active?

            %td{ class: 'buttons' }
              - if User.current.git_allowed_to?(:edit_repository_deployment_credentials, @repository) && (User.current.admin? || User.current == credential.user)
                = link_to l(:button_edit), edit_repository_deployment_credential_path(@repository, credential), class: 'icon icon-edit modal-box'
                = link_to l(:button_delete), repository_deployment_credential_path(@repository, credential), remote: true, method: :delete, confirm: l(:text_are_you_sure), class: 'icon icon-del'
  - else
    %p{ class: 'nodata' }= l(:label_no_data)
